package com.sophie.controller;

import com.sophie.entity.User;
import com.sophie.service.IFollowService;
import com.sophie.service.impl.FollowServiceImpl;
import com.sophie.util.ResultVO;
import com.sophie.util.SendJSONUtil;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "FollowServlet", value = "/FollowServlet")
public class FollowServlet extends BaseServlet {
    IFollowService followService = new FollowServiceImpl();

    //FollowServlet?method=checkFollow
    protected void checkFollow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("------------------------------->检查是否关注");
        String id = request.getParameter("id");
        User user = (User) request.getSession().getAttribute("user");
        ResultVO resultVO = followService.checkFollow(Integer.parseInt(id), user.getId());
        SendJSONUtil.send(resultVO,response);
    }

    //FollowServlet?method=countFans
    protected void countFans(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("------------------------------->计算粉丝数量");
        String id = request.getParameter("id");
        ResultVO resultVO = followService.countFans(Integer.parseInt(id));
        System.out.println("fans = " + resultVO.getData());
        SendJSONUtil.send(resultVO.getData(),response);
    }

    //FollowServlet?method=countFollows
    protected void countFollows(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("------------------------------->计算粉丝数量");
        String id = request.getParameter("id");
        ResultVO resultVO = followService.countFollows(Integer.parseInt(id));
        System.out.println("follows = " + resultVO.getData());
        SendJSONUtil.send(resultVO.getData(),response);
    }



    //FollowServlet?method=none
    protected void none(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("------------------------------->");
    }
}